package com.Case.test;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Scanner;

/**
 * @ClassName test
 * @Author 16799
 * @Date 2025/7/20 15:35
 * @Version 1.0
 * @Description TODO
 *
 * 对照这个案例开了一个包，然后自己写一遍
 **/
public class test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("输入年份和月份(例如：2020-05-01)：");
        String date = sc.next();
        LocalDate currenDate = LocalDate.parse(date);
        LocalDate lastcurrentDate = currenDate.plusMonths(1).minusDays(1);
        ArrayList<String> dates = new ArrayList<>();
        LocalDate start = LocalDate.of(2020,2,1);
        int count = 0;
        while (true){
            LocalDate focusDate = start.plusDays(count);
            count++;
            if (count%4==1){
                dates.add("["+focusDate+"]");
            }else {
                dates.add(focusDate.toString());
            }
            if (focusDate.equals(lastcurrentDate))
                break;
        }

        System.out.println(dates);
        System.out.println("间隔天数：" + (dates.size() - 1));

        ArrayList<String> dates2 = new ArrayList<>();
        int j = dates.size()-1;
        while (true){
            String lastDate = dates.get(j);
            if (lastDate.startsWith("[")&&lastDate.endsWith("]")){
                dates2.add(lastDate);
            }

            if (lastDate.contains(date)){
                break;
            }else {
                j--;
            }
        }
        Collections.reverse(dates2);
        System.out.println(dates2);
        System.out.println("该月休息日天数：" + dates2.size());

        ArrayList<String> dates3 = new ArrayList<>();
        for (int i = 0; i < dates3.size(); i++) {
            String d = dates.get(i);
            if (d.startsWith("[")&&d.endsWith("]")){
                String d2 = d.replaceAll("\\[", "").replaceAll("]", "");
                LocalDate ld = LocalDate.parse(d2);
                int week = ld.getDayOfWeek().getValue();
                if (week == 6 || week == 7){
                    dates3.add(d2+"-周"+week);
                }
            }
        }
        System.out.println(dates3);

    }

}
